<?php

class Skjb_Office_Spreadsheet_Exporter_Excel2007Xml_Relationships
{
    protected $_relationships = array();
    
    public function addRelationship($id, $type, $target)
    {
        $this->_relationships[$id] = array(
            'type'   => $type,
            'target' => $target,
        );
        
        return $this;
    }
    
    public function toXml()
    {
        $xml = new XMLWriter();
        $xml->openMemory();
        $xml->startDocument('1.0', 'UTF-8', 'yes');
        
        $xml->startElement('Relationships');
        $xml->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
        
        foreach ($this->_relationships as $id => $relationship) {
            $xml->startElement('Relationship');
            $xml->writeAttribute('Id', $id);
            $xml->writeAttribute('Type', $relationship['type']);
            $xml->writeAttribute('Target', $relationship['target']);
            $xml->endElement();
        }
        
        $xml->endElement();
        
        $xml->endDocument();
        
        return $xml->outputMemory();
    }
}
